{include file="public_head" /}

<!-- datatables -->
<link href="__STATIC__/js/datatables/jquery.dataTables.min.css" rel="stylesheet" type="text/css"/>
<!-- chk_3 -->
<link href="__STATIC__/css/chk_3.css" rel="stylesheet" type="text/css"/>
<style>
    .table .table{
        background-color: #cafffa;
        margin-bottom: 0;
    }
    .pagination{
        margin:0;
        padding:0;
    }
    font{
        color: blue;
    }
</style>
<body class="nav-md">

<div class="container body">


    <div class="main_container">

        {include file="public_sidebar,public_nav" /}

        <!-- page content -->
        <div class="right_col" role="main">
            <div class="">
                <div class="page-title">
                    <div class="title_left">
                        <h3>
                            商品套餐管理
                        </h3>
                    </div>
                </div>
                <div class="clearfix"></div>

                <div class="row">

                    <div class="col-md-12 col-sm-12 col-xs-12">
                        <div class="x_panel">
                            <div class="x_title">
                                <h2>{$mate_title}</h2>
                                <a style="float: right" href="{:url('client/ShopGoodsCombo/create')}"
                                   class="btn btn-success btn-sm">创建套餐</a>
                                <div class="clearfix"></div>
                            </div>
                            <div class="x_content">
                                <form name="form" id="form" method="get" action="">
                                    <div class="title_left">
                                        <div class="form-group pull-left ">
                                            <div class="input-group">
                                                <input type="text" class="form-control" name="title" id="Title"
                                                       placeholder="输入标题进行查询" value="{:input('title','')}">
                                                <input type="hidden" id="Page" value="{:input('page')}" />
                                            </div>
                                        </div>
                                        &nbsp;&nbsp;&nbsp;&nbsp;
                                        <button type="submit" class="btn btn-primary">搜 索</button>
                                    </div>
                                    <table style="border-bottom:1px solid #ddd;width: 100%;"
                                           class="table table-striped table-bordered table-hover">
                                        <thead>
                                        <tr>
                                            <th style="width: 3%; padding: 10px;">
                                                <input type="checkbox" class="chk_0" id="chk_all" onclick="checkBox(this.checked);"/>
                                            </th>
                                            <th>序号</th>
                                            <th>套餐标题</th>
                                            <th>开始时间</th>
                                            <th>结束时间</th>
                                            <th>套餐总价</th>
                                            <th>原市场总价</th>
                                            <th>是否启用</th>
                                            <th>操作</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        {empty name="combo_list"}
                                        <tr><td colspan="9"><div style='font-size:24px;margin:30px 0;'>没有找到记录</div></td></tr>
                                        {/empty}
                                        {volist name="combo_list" id="item"}
                                        <tr>
                                            <td align="center">
                                                <input type="checkbox" name="id[]" class="chk_0" id="chk_{$item.id}" onclick="checkGoods(this.checked,{$item['id']})" value="{$item.id}"/>
                                            </td>
                                            <td><span>{$key+1+($combo_list->currentPage()-1)*$combo_list->listRows()}</span></td>
                                            <td style="text-indent:10px;" align="left">
                                                <span class="plusSign" id="rowid_{$item['id']}"
                                                      onclick="Display({$item['id']});">&nbsp;</span>
                                                {$item.title}
                                            </td>
                                            <td>
                                                <span>{:date('Y-m-d',$item['begin_time'])}</span>
                                            </td>
                                            <td>
                                                <span>{:date('Y-m-d',$item['end_time'])}</span>
                                            </td>
                                            <td>
                                                <span>&yen;{$item['combo_price']}</span>
                                            </td>
                                            <td>
                                                <span>&yen;{$item['total']}</span>
                                            </td>
                                            <td width="100">
                                                <input type="checkbox" id="checkbox_{$item.id}" class="chk_3" value="{$item.status}" {eq name="item['status']" value="1"}checked{/eq} />
                                                <label style="margin-left: 30px;margin-top: 5px;" onclick="checkAudit({$item['id']},0)" for="checkbox_{$item.id}"></label>
                                            </td>
                                            <td>
                                                <span>
                                                <a href="{:url('client/ShopGoodsCombo/update', ['id' => $item['id'],'search'=>input('title'),'page'=>input('page')])}"
                                                   class="label label-primary">
                                                    <span class="fa fa-pencil"></span>&nbsp;&nbsp;编 辑
                                                </a>

                                                &nbsp;&nbsp;&nbsp;&nbsp;
                                                <a href="javascript:if(confirm('系统会自动删除类别下所有子类别，确定删除吗?')){delAll({$item.id})};" class="label label-danger">
                                                    <span class="fa fa-times"></span>&nbsp;&nbsp;删 除
                                                </a>
                                                </span>
                                            </td>
                                        </tr>
                                        <tr rel="rowpid_{$item.id}">
                                            <td colspan="9">
                                            <table style="border-bottom:1px solid #ddd;width: 100%;"
                                                   class="table table-striped table-bordered table-hover">
                                                <thead>
                                                <tr>
                                                    <th class="hidden-xs">排序</th>
                                                    <th>商品名称</th>
                                                    <th>商品属性</th>
                                                    <th>商品价格</th>
                                                    <th>商品运费</th>
                                                </tr>
                                                </thead>
                                                <tbody>
                                                {volist name="goods_list" id="v"}
                                                {if condition="$item.id eq $v.combo_id"}
                                                <tr>
                                                    <td align="center">
                                                        <span>{$v.sort}</span>
                                                    </td>
                                                    <td style="text-indent:10px;" align="left">
                                                        <span>{$v.shop_goods.title}</span>
                                                    </td>
                                                    <td>
                                                        <span>{$v.attribute}</span>
                                                    </td>
                                                    <td>
                                                        <span>&yen;{$v.shop_goods.price}</span>
                                                    </td>
                                                    <td>
                                                        <span>{neq name="v.shop_goods.freight" value="0"}&yen;{/neq}{$v.shop_goods.freight}</span>
                                                    </td>
                                                </tr>
                                                {/if}
                                                {/volist}
                                            </table>
                                        {/volist}
                                        </td></tr>
                                        </tbody>
                                        <tbody align="left">
                                        <tr>
                                            <td colspan="9">
                                                <span>选择：</span>
                                                <a style="color:#428BCA" href="javascript:delAll_selected();">选择删除</a>
                                                &nbsp;&nbsp;&nbsp;&nbsp;
                                                &nbsp;&nbsp;&nbsp;&nbsp;
                                                <span>总记录<font>{$combo_list->total()}</font>条
                                                    &nbsp;&nbsp;每页<font>{$combo_list->listRows()}</font>条
                                                    &nbsp;&nbsp;当前第<font>{$combo_list->currentPage()}</font>页
                                                    &nbsp;&nbsp;共<font>{$combo_list->lastPage()}</font>页</span>
                                                <span style="float:right;height: 32px;">{$combo_list->render()}</span>
                                            </td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </form>
                            </div>
                        </div>
                    </div>

                </div>
            </div>

        </div>
        <!-- /page content -->
    </div>

</div>
<script>
    $(document).ready(function(){
        $("tr[rel]").slideUp(0);
    });
    //复选框全选
    function checkBox(val){
        $('.chk_0').each(function(){
            this.checked = val;
        })
    }
    function delAll_selected(){
        var page = $('#Page').val();
        if (page == ''){page = 1;}
        var title = $('#Title').val();
        var all = '';
        $("[name='id[]']:checked").each(function (i,o) {
            all += $(o).val()+',';
        })
        if (all == ''){
            layer.msg('请选择删除项!');
        }else{
            if (confirm('确定要删除吗?')){
                $.ajax({
                    url:"{:url('client/shopGoodsCombo/destroy')}",
                    type:'post',
                    dataType:'html',
                    data:{'combo_id':all.slice(0,-1),'page':page},
                    success:function(code){
                        if (code){
                            layer.msg('已删除');
                            location.href = "{:url('client/shopGoodsCombo/index')}?title="+title+"&page="+code;
                        }else{
                            layer.msg('删除失败');
                        }
                    }
                })
            }
        }
    }
    //选择商品
    function checkGoods(val,combo_id){
        $("input[name='id_"+combo_id+"[]']").each(function () {
            this.checked = val;
        })
    }
    //取消选择商品则对应取消父类
    function checkParent(val,combo_id){
        if (val == false){
            $('#chk_all').attr('checked',false);
            $('#chk_'+combo_id).attr('checked',false);
        }
    }
    //删除整个套餐
    function delAll(pid) {
        var page = $('#Page').val();
        if (page == ''){page = 1;}
        var title = $('#Title').val();
        $.ajax({
            url:"{:url('client/shopGoodsCombo/destroy')}",
            type:'post',
            dataType:'html',
            data:{'combo_id':pid,'page':page},
            success:function(code){
                if (code){
                    layer.msg('已删除');
                    location.href = "{:url('client/shopGoodsCombo/index')}?title="+title+"&page="+code;
                }else{
                    layer.msg('删除失败');
                }
            }
        })
    }
    //检测当前正常启用的商品数量
    function check_num(id){
        var num = $(".goods_"+id+":checked").length;
        if (num < 2){
            alert('此套餐下至少有两个已启用的商品!');
            return false;
        }
        return true;
    }
    //启动审核
    function checkAudit(id,type){
        var data = '';
        if (type == 0){
             data = {'combo_id':id};
        }else{
            data = {'id':id}
        }
        $.ajax({
            url: "{:url('client/ShopGoodsCombo/auditing')}",
            type:'post',
            dataType:'html',
            data:data,
            success:function(code){
                if (code){
                    $('#checkbox_'+type).prop('checked',false);
                    layer.msg('状态已更新');
                }else{
                    layer.msg('状态未更改');
                }
            }
        })
    }
    // 展开合并下级
    function Display(id) {
        var rowpid = $("tr[rel='rowpid_" + id + "']");
        var rowid = $("span[id='rowid_" + id + "']");

        if (rowid.attr("class") == "plusSign") {
            rowpid.slideDown(200);
            rowid.attr("class", "minusSign");
        }
        else {
            rowpid.slideUp(200);
            rowid.attr("class", "plusSign");
        }

    }
</script>
{include file="public_foot" /}
<!-- public -->
<script src="__STATIC__/js/public.js"></script>
<!-- layer -->
<script src="__STATIC__/js/layer.js"></script>
